Writing different structs to a file in C++? [on hold]

Posted by user58053 on Stack Overflow See other posts from Stack Overflow or by user58053
Published on 2014-05-29T23:51:46Z Indexed on 2014/05/31 15:27 UTC
Read the original article Hit count: 125

Filed under:
|
|
|
|

I need a way to write structures of three different kinds to a binary file, which later has to be searched. (As in, for example, struct A has two fields, an int and a char; struct B has int and a long; I need to output all structures whose int equals the one given from keyboard).

I understand how to write structs of the same kind to a file and how to search them, but here I am just lost, best thing I came up with is declaring a struct containing all possibly needed fields and leaving the ones I don't need empty, but it really feels wrong, there HAS to be a better way to do that.

I've read about binary files and could not find anything relevant, most examples and tutorials deal with writing one data type. Could anyone point me in the right direction?

EDIT: I am looking for what @Jerry_coffin called database mode, and will probably use one of the existing database systems for that, best way to go, probably. Thank you everybody for the suggestions

© Stack Overflow or respective owner

Related posts about c++

Related posts about c